package com.ssps.back.platform.service.Impl;

import com.ssps.back.platform.service.CommissionService;
import com.ssps.entity.Commission;
import com.ssps.entity.CommissionExample;
import com.ssps.mapper.CommissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author li
 * @time 2020/07/23 16:38:23
 */

@Service
public class CommissionServiceImpl implements CommissionService {

    @Autowired
    CommissionMapper commissionMapper;

    @Override
    public List<Commission> commissionFindAll() {
        List<Commission> commissionList=commissionMapper.selectByExample(null);
        return commissionList;
    }

    @Override
    public void commissionSave(Commission commission) {
        commissionMapper.insert(commission);
    }

    @Override
    public void commissionUpdate(Commission commission) {
        CommissionExample example=new CommissionExample();
        CommissionExample.Criteria criteria = example.createCriteria();
        criteria.andCmidNotEqualTo(commission.getCmid());
        List<Commission> commissionList=commissionMapper.selectByExample(example);
        if (commissionList!=null){
            for (Commission commission1 : commissionList) {
                commission1.setStatus("禁用");
                commissionMapper.updateByPrimaryKeySelective(commission1);
            }
        }
        commissionMapper.updateByPrimaryKeySelective(commission);

    }
}
